/* 判断建筑是否被强化了的函数  只判断是否存在增益PwR*/

import { isInArray } from "@/utils"

export function isPWR(stru:Structure):boolean{
    if (!stru.effects || stru.effects.length <= 0) return false
    else
    {
        if (stru.structureType == 'tower')
        {
            if (!isInArray(getAllEffects(stru),PWR_OPERATE_TOWER))
                return false
        }
        else if (stru.structureType == 'spawn')
        {
            if (!isInArray(getAllEffects(stru),PWR_OPERATE_SPAWN))
                return false
        }
        else if (stru.structureType == 'extension')
        {
            if (!isInArray(getAllEffects(stru),PWR_OPERATE_EXTENSION))
            return false
        }
        else if (stru.structureType == 'terminal')
        {
            if (!isInArray(getAllEffects(stru),PWR_OPERATE_TERMINAL))
            return false
        }
        else if (stru.structureType == 'storage')
        {
            if (!isInArray(getAllEffects(stru),PWR_OPERATE_STORAGE))
            return false
        }
        else if (stru.structureType == 'factory')
        {
            if (!isInArray(getAllEffects(stru),PWR_OPERATE_FACTORY))
            return false
        }
        else if (stru.structureType == 'lab')
        {
            if (!isInArray(getAllEffects(stru),PWR_OPERATE_LAB))
            return false
        }
    }
    return true
}

export function getAllEffects(stru:Structure):PowerConstant[]{
    if (!stru.effects || stru.effects.length <= 0) return []
    var eff_list = []
    for (var effect_ of stru.effects)
    {
        eff_list.push(effect_.effect)
    }
    return eff_list
}

// export function timeEnough(stru:Structure):{}{
//     if (!stru.effects || stru.effects.length <= 0) return null
//     for (var effect_ of stru.effects)
//     {
//         if (effect_.ticksRemaining)
//     }
// }